using UnityEngine;

namespace Gj
{
    public class OverlayHelper : NodeHelper
    {
        public Camera camera;
        public Vector3 offset;
        private Vector3 position;
        private bool show;
        private GameObject target;

        private void Update()
        {
            if (!show) return;
            transform.position = camera.WorldToScreenPoint(target != null ? target.transform.position : position) +
                                 offset;
        }

        private void OnEnable()
        {
            show = true;
            Update();
        }

        private void OnDisable()
        {
            show = false;
        }

        public void SetTarget(GameObject obj)
        {
            target = obj;
        }

        public void SetPosition(Vector3 p)
        {
            position = p;
            target = null;
        }
    }
}